using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class LevelState : AbstractState {
	
	public static string GetCellStateId (int x , int y , int z)
	{
		return x + "," + y + "," + z;
	}

	//CellStates are stored in a dictionary for fast access and to optimize irregularly shaped levels without storing data for empty space.
	private Dictionary<string,CellState> cellStates = null;

	private int xMin = int.MaxValue;
	private int xMax = int.MinValue;
	private int yMin = int.MaxValue;
	private int yMax = int.MinValue;
	private int zMin = int.MaxValue;
	private int zMax = int.MinValue;
	
	public CellState GetCellState (string cellStateId)
	{
		return cellStates[cellStateId];
	}
	
	public CellState GetCellStateAtPos (int x , int y , int z)
	{
		string cellStateId = GetCellStateId(x , y , z);
		CellState cellState = GetCellState(cellStateId);
		return cellState;
	}
	
	public void SetCellStates (Dictionary<string,CellState> value)
	{
		if (ReadOnly)
		{
			LogErrorWriteToReadOnly();
			return;
		}
		cellStates = value;
	}
	
	public int XMin
	{
		get
		{
			return xMin;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			xMin = value;
		}
	}
	
	public int XMax
	{
		get
		{
			return xMax;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			xMax = value;
		}
	}
	
	public int YMin
	{
		get
		{
			return yMin;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			yMin = value;
		}
	}
	
	public int YMax
	{
		get
		{
			return yMax;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			yMax = value;
		}
	}
	
	public int ZMin
	{
		get
		{
			return zMin;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			zMin = value;
		}
	}
	
	public int ZMax
	{
		get
		{
			return zMax;
		}
		set
		{
			if (ReadOnly)
			{
				LogErrorWriteToReadOnly();
				return;
			}
			zMax = value;
		}
	}
}
